import { inject } from '@angular/core';
import { AppService } from './services/app.service';
import { LoginInfoService } from './services/login-info.service';

export const authGuard = () => {
  const _loginInfoService = inject(LoginInfoService);
  const _appService = inject(AppService);

  _loginInfoService.isLoggedIn.subscribe((value) => {
    if (value) {
      console.log('AuthGuard OK');
      return true;
    } else {
      console.log('AuthGuard logout');
      _appService.logout();
      return false;
    }
  });
}
